#include <setjmp.h>
#include <stdio.h>
#include <stdbool.h>
#define MAX_COUNT 100
static int i=-1;
jmp_buf jmp_buf_array[ MAX_COUNT ];

#define TRY	\
	jmp_buf hello;		\
	memcpy( & jmp_buf_array[++i] , hello , sizeof(jmp_buf) );\
	if( 0== setjmp( jmp_buf_array[i]) )\


#define CATCH 	\
	else	

#define END_TRY_CATCH	\
	i--;

#define THROW( value )	\
	longjmp( jmp_buf_array[i--] , value);
void g(){
	THROW(1);
}
void f(){
	TRY{
		g();
	}CATCH{
		printf("hello\n");
		g();
	}END_TRY_CATCH

}

/*jmp_buf buf;
void g(int n);
void h(int n);
int n = 600000;
void f(void)
{
int x[n]; // valid: f is not terminated
int retval=setjmp(buf);
printf("the retval is %d\n",retval);
g(n);
}
void g(int n)
{
int a[n]; // a may remain allocated
h(n);
}
void h(int n)
{
int b[n]; // b may remain allocated
longjmp(buf, 2); // might cause memory loss
}
*/
int main(){
//	bool i;
//	printf("%s%d\n",__FUNCTION__,i);
	TRY{
		f();
	}CATCH{
		printf("in catch\n");
	}END_TRY_CATCH		
	return 0;
}
